package com.dm.wallpaper.library.helpers;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;

public class AnimatorHelp {

    public static class SimpleStateChangedListener implements Animator.StateChangedListener {

        @Override
        public void onStart(Animator animator) {

        }

        @Override
        public void onStop(Animator animator) {

        }

        @Override
        public void onCancel(Animator animator) {

        }

        @Override
        public void onEnd(Animator animator) {

        }

        @Override
        public void onPause(Animator animator) {

        }

        @Override
        public void onResume(Animator animator) {

        }
    }


    public static void scaleXYAnimator(Component component, SimpleStateChangedListener changedListener) {
        component.setScaleX(0.0F);
        component.setScaleY(0.0F);
        component.setAlpha(0.0F);
        AnimatorProperty animatorProperty = component.createAnimatorProperty();
        animatorProperty.setDuration(200).
                scaleX(1.0F).scaleY(1.0F).alpha(1.0F)
                //  .setInterpolator(animator.interpolator)
                .setStateChangedListener(new Animator.StateChangedListener() {
                    @Override
                    public void onStart(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onStart(animator);
                        }
                    }

                    @Override
                    public void onStop(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onStop(animator);
                        }
                    }

                    @Override
                    public void onCancel(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onCancel(animator);
                        }
                    }

                    @Override
                    public void onEnd(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onEnd(animator);
                        }
                    }

                    @Override
                    public void onPause(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onPause(animator);
                        }
                    }

                    @Override
                    public void onResume(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onResume(animator);
                        }
                    }
                }).start();
    }

    public static void scaleXYAnimatorToHid(Component component, SimpleStateChangedListener changedListener) {
        component.setScaleX(1.0F);
        component.setScaleY(1.0F);
        component.setAlpha(1.0F);
        AnimatorProperty animatorProperty = component.createAnimatorProperty();
        animatorProperty.setDuration(200).
                scaleX(0.0F).scaleY(0.0F).alpha(0.0F)
                //  .setInterpolator(animator.interpolator)
                .setStateChangedListener(new Animator.StateChangedListener() {
                    @Override
                    public void onStart(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onStart(animator);
                        }
                    }

                    @Override
                    public void onStop(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onStop(animator);
                        }
                    }

                    @Override
                    public void onCancel(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onCancel(animator);
                        }
                    }

                    @Override
                    public void onEnd(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onEnd(animator);
                        }
                    }

                    @Override
                    public void onPause(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onPause(animator);
                        }
                    }

                    @Override
                    public void onResume(Animator animator) {
                        if (changedListener != null) {
                            changedListener.onResume(animator);
                        }
                    }
                }).start();
    }
}
